package net.yunxinyong.cec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.yunxinyong.cec.entity.Cec711ThreeEntity;
import net.yunxinyong.cec.entity.Cec711ThreeEntityExample;
import net.yunxinyong.cec.mapper.Cec711ThreeMapper;
import net.yunxinyong.cec.service.Cec711ThreeService;
import net.yunxinyong.cec.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class Cec711ThreeServiceImpl implements Cec711ThreeService {

    @Autowired
    private Cec711ThreeMapper cec711ThreeMapper;

    @Override
    public PageBean<Cec711ThreeEntity> findAll(int page,int rows,Cec711ThreeEntity cecThree) {
        Cec711ThreeEntityExample cec711ThreeEntityExample = new Cec711ThreeEntityExample();
        Cec711ThreeEntityExample.Criteria criteria = cec711ThreeEntityExample.createCriteria();
        if(cecThree.getId()!=null){
            criteria.andIdEqualTo(cecThree.getId());
        }
        if (page != 0 && rows != 0) {
            PageHelper.startPage(page, rows);
        }
        List<Cec711ThreeEntity> list = cec711ThreeMapper.selectByExample(cec711ThreeEntityExample);
        //设置分页信息
        PageBean<Cec711ThreeEntity> pageBean = new PageBean<>();
        PageInfo<Cec711ThreeEntity> pageInfo = new PageInfo<>(list);
        pageBean.setTotal(pageInfo.getTotal());
        pageBean.setTotalPages(pageInfo.getPages());
        pageBean.setPageDatas(list);
        return pageBean;
    }

    @Override
    public int updateById(int id, int status) {
        Cec711ThreeEntity cec711ThreeInvestmentSituation = new Cec711ThreeEntity();
        cec711ThreeInvestmentSituation.setId(id);
        cec711ThreeInvestmentSituation.setStatus(status);
        cec711ThreeInvestmentSituation.setUpdateTime(new Date());
        int count = cec711ThreeMapper.updateByPrimaryKeySelective(cec711ThreeInvestmentSituation);
        return count;
    }

    @Override
    public int deleteById(int id) {
        Cec711ThreeEntity cec711ThreeInvestmentSituation = new Cec711ThreeEntity();
        cec711ThreeInvestmentSituation.setId(id);
        //删除企业信息，把status字段的值改为1:值为1:删除，值为2:正常
        cec711ThreeInvestmentSituation.setStatus(1);
        int count = cec711ThreeMapper.updateByPrimaryKeySelective(cec711ThreeInvestmentSituation);
        return count;
    }

    @Override
    public List<Cec711ThreeEntity> findThreeByBaseId(int baseid) {
        Cec711ThreeEntityExample cec711ThreeEntityExample = new Cec711ThreeEntityExample();
        Cec711ThreeEntityExample.Criteria criteria = cec711ThreeEntityExample.createCriteria();
        criteria.andBaseIdEqualTo(baseid);
        List<Cec711ThreeEntity> list = cec711ThreeMapper.selectByExample(cec711ThreeEntityExample);

        return list;
    }

    @Override
    public int insertThree(int baseid) {
        Cec711ThreeEntity cec711ThreeInvestmentSituation = new Cec711ThreeEntity();

        cec711ThreeInvestmentSituation.setBaseId(baseid);
        //更改表时间
        cec711ThreeInvestmentSituation.setUpdateTime(new Date());
        //创建表时间
        cec711ThreeInvestmentSituation.setCreateTime(new Date());
        int count = cec711ThreeMapper.insertSelective(cec711ThreeInvestmentSituation);
        return count;
    }
}
